package com.ican.dao.product;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ican.common.hibernate.HibernateDao;
import com.ican.common.hibernate.Page;
import com.ican.domain.product.OptionValue;

@Repository("optionValueDao")
public class OptionValueDao extends HibernateDao<OptionValue, Integer> {

    public void createOptionValue(){
        String sql = "{call p_product_option_value()}";
        this.createSqlQuery(sql).executeUpdate();
    }
    
    public Page<OptionValue> findAllOptionValue2Syn(Page<OptionValue> page) {
        return findPage(page, "from OptionValue where valueCode is null");
    }
    
    public List<OptionValue> findAllOptionValue(String nameCode, String optionValue, Integer langId) {
        return find("from OptionValue where nameCode = '" + nameCode + 
        		"' and optionValue = '" + optionValue + "' and langId = " + langId);
    }
    
    public void updateOptionValueName(Integer id, String optionValueNew){
        String hql = "update OptionValue set optionValue = '" + optionValueNew + "' where id = " + id;
        this.batchExecute(hql);
    }
    
    public void updateOptionValueCode(Integer id, String valueCode, Integer ocOptionValueId){
        String hql = "update OptionValue set valueCode = '" + valueCode + "', ocOptionValueId = " + ocOptionValueId + " where id = " + id;
        this.batchExecute(hql);
    }
    
    public OptionValue findOptionValueByValueAndLang(Integer optionId, String optionValue, Integer langId){
        String hql = "from OptionValue where optionId = " + optionId +
        		" and optionValue = '" + optionValue + "' and langId = " + langId;
        return this.findUnique(hql);
    }
    
    public OptionValue findOptionValueByValueCodeAndLang(Integer optionId, String valueCode, Integer langId){
        String hql = "from OptionValue where optionId = " + optionId +
        		" and valueCode = '" + valueCode + "' and langId = " + langId;
        return this.findUnique(hql);
    }
}
